package cn.huiyunche.base.service.interfaces;

import cn.huiyunche.base.service.form.*;
import cn.huiyunche.base.service.model.SOrder;
import cn.huiyunche.base.service.model.SOrderExample;
import cn.huiyunche.base.service.vo.*;
import cn.huiyunche.tools.basic.exceptions.BusinessException;

import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @ClassName: ShipService
 * @Description: 客户订单接口
 * @author: Aaron
 * @date: 2016年5月10日 下午12:38:28
 */
public interface SOrderService {

    /**
     * @param excelVo Excel模板数据
     * @Title: add
     * @Description: Excel数据导入的方式下单
     * @return: Map<String, Object>
     */
    Map<String, Object> add(OrderByExcelVo excelVo, Boolean isPublish) throws Exception;

    /**
     * @param soiv Excel模板数据
     * @Title: addByExcel
     * @Description: Excel数据导入的方式下单
     * @return: Map<String, Object>
     */
    Map<String, Object> addByExcel(SOrderImportedVo soiv) throws Exception;

    /**
     * @param form order表单
     * @Title: add
     * @Description: 添加订单（下单）
     * @return: Map<String, Object>
     */
    Map<String, Object> add(OrderForm form) throws Exception;

    /**
     * @param id 订单id
     * @param b  是否是重新发布
     * @Title: publish
     * @Description: 发布订单
     * @return: int
     */
    int publish(long id, boolean b) throws Exception;

    /**
     * @param id   订单id
     * @param b    是否是重新发布
     * @param user
     * @Title: publish
     * @Description: 发布订单 托运个人支付成功 调用发布订单接口
     * @return: int
     */
    int kylePublish(long id, boolean b, UserVo user) throws Exception;

    /**
     * @param id                    订单id
     * @param hasContainsInvoiceFee 是否包含税费
     * @Title: getById
     * @Description: 获取订单
     * @return: Order
     */
    OrderVo getById(long id, Boolean hasContainsInvoiceFee);

    /**
     * @param customerOrderId 客户订单id
     * @param reason          取消原因
     * @Title: cancel
     * @Description: 取消订单
     * @return: boolean
     */
    boolean cancel(long customerOrderId, String reason, boolean isSystem) throws Exception;

    /**
     * @param orderid    订单id
     * @param createDate 保存时间
     * @Title: saveOrderToRedis
     * @Description: 添加订单信息到Redis中
     * @return: void
     */
    void saveOrderToRedis(String orderid, Date createDate);

    /**
     * @param id
     * @Title: getSurplusTimeByOrder
     * @Description: 根据orderid返回剩余时间 单位秒
     * @return: long
     */
    long getSurplusTimeByOrder(String id);

    /**
     * @param id
     * @Title: cleanOrderFromRedis
     * @Description: 确定报价后从redis中删除订单记录，清除超时
     * @return: boolean
     */
    boolean cleanOrderFromRedis(String id);

    /**
     * @param id        订单id
     * @param status    流程状态
     * @param payStatus 付款状态
     * @Title: updateStatus
     * @Description: 更新客户订单状态
     * @return: boolean
     */
    boolean updateStatus(long id, int status, int payStatus, boolean flag);

    /**
     * @param id
     * @Title: 根据客户订单ID返回订单支付状态
     * @Description: 根据客户订单ID返回订单支付状态
     * @return: int
     */
    int getPayStatusById(long id);

    /**
     * @param id
     * @Title: 根据ID获取订单
     * @Description: 根据客户订单ID获取订单
     * @return: Result<Order>
     */
    Result<SOrder> getOrderById(long id);

    /**
     * @param orderId
     * @param paystatus
     * @Title: 更新客户订单支付状态
     * @Description: 更新客户订单支付状态
     * @return: boolean
     */
    boolean updateOrderPayStatusForRedis(long orderId, int paystatus);

    /**
     * 确认收车
     *
     * @param id 主键ID
     * @return
     * @throws BusinessException
     */
    boolean confirmReceive(long id) throws Exception;

    SOrder selectByPrimaryKey(long orderId);

    SOrderVo selectById(long sorderId);

    List<SOrder> selectByExample(SOrderExample search);

    /**
     * @param id         订单id
     * @param isPick     是否上门提车
     * @param isDeliv    是否送车上门
     * @param productid  物流产品id
     * @param hasInvoice 是否有发票 (是否计算发票税费)
     * @Title: computeFees
     * @Description: 计算客户订单各种费用的总计
     * @return: Map<String,Object>
     */
    Map<String, Object> computeFees(Long id, Boolean isPick, Boolean isDeliv, Long productid, Boolean hasInvoice) throws Exception;

    /**
     * @param customerOrderId 客户服务订单
     * @Title: getUnpaidOrder
     * @Description: 根据客户订单id查询未付款订单（个人订单）
     * @return: SOrder
     */
    SOrder getUnpaidOrder(long customerOrderId);

    Map<String, Object> selectByStatus(PageVo page, int status) throws Exception;

    Result<Object> changeStatus(Long id);

    Object alreadystartList(PageVo page) throws Exception;

    Object completedList(PageVo page) throws Exception;

    Object changeStatusOrderDone(Long id);

    Result<Object> selectTichePic(Long orderId, boolean flag);

    Result<Object> saveOrderAttach(String key, int type, Long orderId);

    Map<String, Object> selectCarInsuranceDetails(PageVo page);

    /**
     * @param customerOrderId 客户订单id
     * @Title: getSOrderByCOrderId
     * @Description: 查询客户订单的物流追踪
     * @return: COrderLogisticsVo
     */
    COrderLogisticsVo getSOrderByCOrderId(long customerOrderId) throws Exception;

    List<String[]> exportCarInsurances(int length);

    SOrderInfoVo orderDetail(Long orderId);

    Object changeOrderStatus(Long id, int status);

    /**
     * 根据服务订单ID 修改客户订单状态
     *
     * @param sorderId
     * @return
     */
    boolean updateOrderStatusBySid(Long sorderId);

    /**
     * @param customerOrderId 客户订单id
     * @Title: getExInfoList
     * @Description: 获取客户订单的关联的运单的提车信息
     * @return: Collection<ExAndDeInfoVo>
     */
    Collection<ExAndDeInfoVo> getExInfoList(long customerOrderId);

    /**
     * @param customerOrderId 客户订单id
     * @Title: getDeInfoList
     * @Description: 获取客户订单的关联运单的提车信息
     * @return: Collection<ExAndDeInfoVo>
     */
    Collection<ExAndDeInfoVo> getDeInfoList(long customerOrderId);

    /**
     * @param form 查询条件表单
     * @return
     * @Title: getCwaybillsByConditions
     * @Description: 查询客户订单关联运单的服务订单信息
     * @return: List<COrderTrackVo>
     */
    Map<String, Object> getCwaybillsByConditions(COrderTrackForm form, PageVo page) throws Exception;

    /**
     * @param customerOrderId 客户订单id
     * @Title: delete
     * @Description: 删除客户客户订单（保存状态的）
     * @return: void
     */
    void delete(long customerOrderId);

    /**
     * @param feeForm 费用查询参数
     * @Title: calculateFees
     * @return: Map<String,Object>
     */
    Map<String, Object> calculateFees(QueryFeesForm feeForm) throws Exception;

    /**
     * @param params
     * @Title: queryFees
     * @Description: 查询费用
     * @return: Collection<BProductCoefficientVo>
     */
    Collection<BProductCoefficientVo> calculateFees(FeesSearchForm params) throws Exception;

    /**
     * @param page     分页参数
     * @param costatus 客户订单状态
     * @param sostatus 服务订单状态
     * @Title: getListByStatuss
     * @Description: 根据客户订单状态查询订单列表
     * @return: Map<String,Object>
     */
    Map<String, Object> getListByStatuss(PageVo page, List<Integer> costatus, List<Integer> sostatus) throws Exception;

    /**
     * @param page 分页参数
     * @Title: getSavedList
     * @Description: 已保存客户订单列表
     * @return: Map<String,Object>
     */
    Map<String, Object> getSavedList(PageVo page) throws Exception;

    /**
     * @param page 分页参数
     * @Title: getWaitingReceiveList
     * @Description: 待接单客户订单列表
     * @return: Map<String,Object>
     */
    Map<String, Object> getWaitingReceiveList(PageVo page) throws Exception;

    /**
     * @param page 分页参数
     * @Title: getImplementingList
     * @Description: 查询待接单（已发布）订单列表
     * @return: Map<String,Object>
     */
    Map<String, Object> getPublishedList(PageVo page) throws Exception;

    /**
     * @param page 分页参数
     * @Title: getPendingPaymentList
     * @Description: 查询待付款订单列表
     * @return: Map<String, Object>
     */
    Map<String, Object> getPendingPaymentList(PageVo page) throws Exception;

    /**
     * @param page 分页参数
     * @Title: getPendingPaymentList
     * @Description: 查询执行中订单列表
     * @return: Map<String,Object>
     */
    Map<String, Object> getInTransitList(PageVo page) throws Exception;

    /**
     * @param page 分页参数
     * @Title: getCompletedList
     * @Description: 已交车客户订单列表
     * @return: Map<String,Object>
     */
    Map<String, Object> getCompletedList(PageVo page) throws Exception;

    /**
     * @param page 分页参数
     * @Title: getDoneList
     * @Description: 查询已完成订单列表
     * @return: Map<String, Object>
     */
    Map<String, Object> getDoneList(PageVo page) throws Exception;

    /**
     * @param page 分页参数
     * @Title: getAllList
     * @Description: 查询全部客户订单列表
     * @return: Map<String,Object>
     */
    Map<String, Object> getAllList(PageVo page) throws Exception;

    /**
     * Calculate intracity fees map.
     *
     * @param depaId       the depa id
     * @param destId       the dest id
     * @param trailerId    the trailer id
     * @param vehicleNum   @return the map
     * @param deliveryDate the delivery date
     * @param deliveryTime @return the map
     * @return the map
     */
    Map<String, Object> calculateIntracityFees(Long depaId, Long destId, Integer trailerId, Integer vehicleNum, Date deliveryDate, String deliveryTime) throws Exception;

    /**
     * Add intracity order.
     *
     * @param form the form
     */
    void addIntracityOrder(IntracityOrderForm form) throws Exception;

    /**
     * Update order by primary key selective.
     *
     * @param order the order
     */
    void updateOrderByPrimaryKeySelective(SOrder order);
}
